package org.point.service.impl;

import java.io.Serializable;

import org.point.common.dao.BaseDAO;
import org.point.common.service.impl.BaseServiceImpl;
import org.point.dao.LoginDao;
import org.point.domain.Login;
import org.point.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service("loginService")
public class LoginServiceImpl extends BaseServiceImpl<Login, Serializable> implements LoginService {

	@Autowired
	private LoginDao dao;

	// 这句必须要加上。不然会报空指针异常，因为在实际掉用的时候不是BaseDao调用，而是这个dao
	@Override
	public void setBaseDAO(BaseDAO<Login, Serializable> baseDAO) {
		super.setBaseDAO(dao);
	}

	public Integer doLogin(Login record) {
		// sign : 账号密码正确则返回1；账号正确，密码错误则返回0；账号错误则返回-1
		Integer sign = -1;
		Login login = dao.getLoginByNP(record);
		if (login != null && login.getLoginEmail().equals(record.getLoginEmail())) {
			if (!login.getLoginPwd().equals(record.getLoginPwd())) {
				sign = 0;
				return sign;
			} else {
				sign = 1;
				return sign;
			}
		}
		return sign;
	}

	public Integer checkLoginEmail(Login record) {
		Integer sign = dao.getLoginByLoginEmail(record);
		return sign;
	}


}
